package com.sunny.myproject.system.action;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import com.sunny.myproject.system.service.MenuService;

/**
 *
 * @author sunnynie
 * @email sunnynie89@gmail.com
 */
@Controller
public class HomeAction {

	@Autowired
	private MenuService service;
	
    @RequestMapping(value="/login")
    public String toLogin(Model model,HttpServletRequest request){
    	List<Criterion> criterions = new ArrayList<Criterion>();
    
    	criterions.add(Restrictions.eq("top", "1"));
    	model.addAttribute("menus", service.list(criterions));
        return "home";
    }
    
    @RequestMapping(value="/viewPage")
    public String toView(Model model,HttpServletRequest request){
    	
    	String id = request.getParameter("id");
    	
    	List<Criterion> criterions = new ArrayList<Criterion>();
        
    	criterions.add(Restrictions.eq("father.id", Long.parseLong(id)));
    	model.addAttribute("menus", service.list(criterions));
    	return "view";
    }
    
}
